from email.mime.text import MIMEText
from email.utils import formataddr

import smtplib

my_sender = 'linuxeer@163.com'
my_user = 'xuchaosheng@trend-data.cn'

def mail(text):
    ret = True
    try:
        msg = MIMEText(text, 'plain', 'utf-8')
        msg['From'] = formataddr(["指南针爬虫汇报", my_sender])
        msg['To'] = formataddr(["charsen", my_user])
        msg['Subject'] = "关于指南针店铺数据抓取"

        server = smtplib.SMTP("smtp.163.com", 25)
        server.login(my_sender, "303017aaa")
        server.sendmail(my_sender, [my_user, ], msg.as_string())
        server.quit()
    except Exception:
        ret = False

    return ret
